package com.zmn.brs.task.listenter.okr;

import com.alibaba.fastjson.JSONObject;
import com.zmn.brs.business.interfaces.objective.ObjectivePrincipalBService;
import com.zmn.brs.common.constant.BrsMqConst;
import com.zmn.brs.dto.PrincipalDelDTO;
import com.zmn.brs.dto.PrincipalEditDTO;
import com.zmn.manager.mq.annotation.AliyunMQHandler;
import com.zmn.manager.mq.annotation.AliyunMQListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 描述： OKR 目标责任人消息监听
 *
 * @author chongw
 * @since 2021-07-20 14:11
 */
@Slf4j
@Component
@AliyunMQListener(topic = "${spring.mq.topic.okr}")
public class ObjectivePrincipalMessageQueueListener {

    final static String TAG = "OKR目标责任人消息监听";

    @Resource
    ObjectivePrincipalBService objectivePrincipalBService;

    @AliyunMQHandler(topic = "${spring.mq.topic.okr}", tags = BrsMqConst.MESSAGE_OKR_PRINCIPAL_SET_SUBGOAL)
    public void setHandler(String message) {
        log.info("[{}], 接收到新的消息message, 原始消息:{}", TAG, message);
        PrincipalEditDTO dto = JSONObject.parseObject(message, PrincipalEditDTO.class);
        objectivePrincipalBService.edit(dto);
    }

    @AliyunMQHandler(topic = "${spring.mq.topic.okr}", tags = BrsMqConst.MESSAGE_OKR_PRINCIPAL_DEL)
    public void delHandler(String message) {
        log.info("[{}], 接收到新的消息message, 原始消息:{}", TAG, message);
        PrincipalDelDTO dto = JSONObject.parseObject(message, PrincipalDelDTO.class);
        objectivePrincipalBService.del(dto);
    }

}
